package com.yulan.bankback.controller.bank;

import com.yulan.bankback.aop.Authorization;
import com.yulan.bankback.entity.result.RetResponse;
import com.yulan.bankback.entity.result.RetResult;
import com.yulan.bankback.entity.vo.SafeVo;
import com.yulan.bankback.service.bank.SafeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/safe")
public class SafeController {

    @Autowired
    private SafeService safeService;

    @Authorization({"admin", "bank_user"})
    @GetMapping("/info/{uid}")
    public RetResult geInfo(@PathVariable("uid") String uid){
        if(StringUtils.isBlank(uid)) return RetResponse.makeErrRsp("用户ID不能为空");
        SafeVo res = safeService.getUserSafeInfo(uid);
        return res != null ? RetResponse.makeOKRsp(res) : RetResponse.makeErrRsp("不存在该用户的数据");
    }

    @Authorization({"admin", "bank_user"})
    @PostMapping("/loginEvent")
    public RetResult getLoginEvent(String uid, String type,  String start, String end){
        if(StringUtils.isBlank(uid)) return RetResponse.makeErrRsp("用户ID不能为空");
        if(StringUtils.isBlank(start)) return RetResponse.makeErrRsp("开始时间不能为空");
        if(StringUtils.isBlank(end)) return RetResponse.makeErrRsp("结束时间不能为空");
        return RetResponse.makeOKRsp(safeService.getEventInterval(uid, type, start, end));
    }

    @Authorization({"admin", "bank_user"})
    @GetMapping("/safe_notice")
    public RetResult getAllSafeNotice(){
        return RetResponse.makeOKRsp(safeService.getAllSafeNoticesId());
    }
}
